<?php 
include("header.php");
include("navigation.php");
include("database.php");
?>

    <!-- Columns -->
    <div class="cols-top"></div>
    <div class="cols box">

        <!-- Content -->
        <div class="content">
        
            
            <?php if (isset($_SESSION['nick'])){ ?>
            <p> 
            <?php
            	$cod_video = $_REQUEST['v'];
				$consulta=mysql_query("SELECT * FROM videos, usuario WHERE usuario.id = id_usuario AND '$cod_video' = videos.id",$enlace);
				
			if(mysql_num_rows($consulta) != 0){
			
			for($inicio=1; $dato = mysql_fetch_array($consulta); $inicio+=1){
			?>
				<!-- Perex -->
            <div class="perex">

                <p><?php echo $dato['titulo']; ?></p>
				
            </div> <!-- /perex -->
		
		<div class="content-box box">
            
                <p class="nom t-center">
                    <?php $ruta_rep = "http://izeup.com/video/" . $dato['nombre_arch'];?>
                    
					<div class="skinpreview"><script type="text/javascript" src="/js/swfobject1.5.js"></script> 
					<div name="mediaspace" id="mediaspace"> 
					<script type="text/javascript"> 
						var so = new SWFObject('http://player.longtailvideo.com/player5.1.swf','single','600','400','0');
						so.addParam("allowfullscreen","true");
						so.addParam("allowscriptaccess","always");
						so.addParam("wmode","opaque");
						so.addVariable("file", "<?php echo $ruta_rep; ?>");
							
						//Modify path based on select box dropdown for PNG or SWF
						so.addVariable("skin", "http://www.longtailvideo.com/files/skins/stijl/4/stijl.swf");
						so.write('mediaspace');
					</script></div></div> 
					
					<p>Visitas:<b> <?php echo $dato['visitas']; ?></b></p>
					<?php 
						$visitas = $dato['visitas'];
						$visitas ++;
						$mas_visitas = "UPDATE videos SET visitas = '$visitas' WHERE id =" . $cod_video .";";
						$consulta = mysql_query($mas_visitas, $enlace);
					?>
					
					<?php 
						$consulta=mysql_query("SELECT * FROM videos WHERE '$cod_video' = videos.id",$enlace);
						$dato = mysql_fetch_array($consulta);
						$_SESSION['videoid'] = $dato['id'];
					?>
					<div class="reportar">
						<a href="functions/inadecuado.php?v=<?php echo $dato['id'];?>" target="_blank">Reportar problema con el video</a>
					</div>
					<div class="compartir">
						<a href="http://twitter.com/home?status=Estoy viendo <?php echo $dato['titulo'];?> - http://izeup.com/video.php?v=<?php echo $dato['id'];?> #izeup" target="_blank"><img src="design/twitter_icon.png" width="32" height="32" /></a>
						<a href="http://www.facebook.com/sharer.php?u=http://izeup.com/video.php?v=<?php echo $dato['id'];?>&t=Estoy viendo <?php echo $dato['titulo'];?>" target="_blank"><img src="design/facebook.png" width="32" height="32" /></a>
					</div>
                </p>
				<br /><br /><br />
				<?php echo "<b>Sinopsis: </b>" . $dato['descripcion'];?>
            </div> <!-- /content-box -->
            
		<?php 
			}//fin del for
			}//fin del if
            else{
				echo "Error";		
		}
		?>
		<h3>Comentarios</h3>
		
		
		<?php 
			
			$usuario = $_SESSION['nick'];
            $consulta=mysql_query("SELECT * FROM usuario WHERE nick = '$usuario'", $enlace);
			$resultado=mysql_fetch_array($consulta);
			   
		?>
		
		<?php 
			$comentario = "SELECT * FROM comentarios WHERE id_video = " . $cod_video ." ORDER BY fecha desc;";
			//echo $comentario;
			$comentario2 = mysql_query($comentario, $enlace);
			$comentario4 = mysql_fetch_array($comentario2);
			
			if(mysql_num_rows($comentario2) != 0){
				$id_comentarista = $comentario4['id_usuario'];
				//echo $id_comentarista;
				$consulta = mysql_query("SELECT avatar, web, nick FROM usuario WHERE id = '$id_comentarista'; ", $enlace);
				$dato = mysql_fetch_array($consulta);
				for($inicio = 1; $comentario3 = mysql_fetch_array($comentario2); $inicio +=1){		
		?>
					<p><img src="design/avatar/<?php echo $dato['avatar'];?>" width="32" height="32" alt="" class="f-left" /> <b>Escrito por <a href="<?php echo $dato['web'];?>" target="_blank"><?php echo $dato['nick'];?></a> (<?php echo $comentario3['fecha'];?>)</b><br />
            		<?php echo $comentario3['comentario'];?></p>
		
		<?php
				} 
			}// fin del if que comprueba si hay comentarios
			else echo "No hay ning&uacute;n comentario. &iquest;A qu&eacute; esperas?"
		?>
		
		<form action="functions/enviar_comentario.php" method="post">
                <div class="content-box box">

                    
                    <input type="hidden"  name="id" value="<?php echo $cod_video;?>"  />
                    <?php 
                    	if(isset($_SESSION['nick'])){
                    ?>
                    		<input type="hidden" size="65" class="input" name="nombre" value="<?php echo $usuario;?> " /></p>
		                    <input type="hidden" size="65" class="input" name="mail" value="<?php echo $resultado['mail'];?>" /></p>
                    
        		            Logueado como: <?php echo $_SESSION['nick'];?>. <a href="logout.php">Salir</a>
                    <?php 
                    	
                    	}
                    	else{
                    ?>                   
                    		<p class="nomt"><strong>Nick:</strong><br />
                    		<input type="text" size="65" class="input" name="nombre" value="<?php echo $usuario;?> " /> (Requerido)</p>

                    		<p><strong>Mail:</strong><br />
                    		<input type="text" size="65" class="input" name="mail" value="<?php echo $resultado['mail'];?>" /> (Requerido)</p>
					<?php 
					
                    	}
					
					?>
                    <p><strong>Comentario:</strong><br />
                    <textarea cols="95" rows="10" class="input" name="comentario" style="width:550px; height:150px;"></textarea></p>

                    <p class="nomb t-center"><input type="image" src="design/btn-ok.gif" value="OK" /></p>

                </div> <!-- /content-box -->
     </form>
		</p>

           <?php 
			} 
			else {
				echo "P&aacute;gina no v&aacute;lida. Prueba a loguearte primero o <a href=\"register.php\">registrarte</a>";
			}
			?>
        </div> <!-- /content -->
        

       <?php
       		include("sidebar.php");
       ?>

    <!-- Footer -->
    <?php include("footer.php");?> 
    <!-- /footer -->

</div> <!-- /main -->

</body>
</html>
